<template>
  <div style="margin-top: 20px">
    <el-row>
      <el-input v-model="input" placeholder="请输入姓名" style="width: 300px" />&nbsp;
      <el-button type="primary" icon="el-icon-search" @click="queryDatas()">查询</el-button>
      <!--      <el-button @click="dialogFormVisible = true" type="warning" icon="el-icon-circle-plus-outline">新增</el-button>-->
    </el-row>
    <br>
    <div>
      <el-table
        v-loading="loading"
        :data="tableData.slice((currentPage-1)*pageSize,currentPage*pageSize)"
        border
      >
        <el-table-column
          fixed
          prop="fileNumber"
          label="档案号"
        />
        <el-table-column
          prop="name"
          label="姓名"
        />
        <el-table-column
          prop="sex"
          label="性别"
        />
        <el-table-column
          prop="age"
          label="年龄"
        />
        <el-table-column
          prop="status"
          label="状态"
        />
        <el-table-column
          prop="diseaseid"
          label="人群分类"
        />
        <el-table-column
          prop="user_name"
          label="健康管理师"
        />
        <el-table-column
          prop="phoneNumber"
          label="手机号码"
        />
        <el-table-column
          prop="regTime"
          label="注册时间"
        />
        <el-table-column
          fixed="right"
          label="操作"
          width="300"
        >
          <template v-slot="scope">
            <el-button type="primary" size="small" icon="el-icon-view" @click="opensave = true;opensavex(scope.row.id);">查看</el-button>
            <!--            <el-button @click="Updates(scope.row.name)" type="warning" size="small" icon="el-icon-edit">编辑</el-button>-->
            <el-button type="danger" size="small" icon="el-icon-delete" @click="open(scope.row.id);">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
    <!--    <div>-->
    <!--      <el-dialog title="添加" :before-close="openUAdd" :visible.sync="dialogFormVisible">-->
    <!--        <el-form :model="form">-->
    <!--          <el-form-item label="活动名称" :label-width="formLabelWidth">-->
    <!--            <el-input v-model="form.name" autocomplete="off"></el-input>-->
    <!--          </el-form-item>-->
    <!--          <el-form-item label="活动区域" :label-width="formLabelWidth">-->
    <!--            <el-select v-model="form.region" placeholder="请选择活动区域">-->
    <!--              <el-option label="区域一" value="shanghai"></el-option>-->
    <!--              <el-option label="区域二" value="beijing"></el-option>-->
    <!--            </el-select>-->
    <!--          </el-form-item>-->
    <!--        </el-form>-->
    <!--        <div slot="footer" class="dialog-footer">-->
    <!--          <el-button @click="openUAdd()">取 消</el-button>-->
    <!--          <el-button type="primary" @click="openOk('添加成功');dialogFormVisible = false">确 定</el-button>-->
    <!--        </div>-->
    <!--      </el-dialog>-->
    <!--    </div>-->
    <!--    <div>-->
    <!--      <el-dialog title="修改" :before-close="openUpdate" :visible.sync="UpdateData">-->
    <!--        <el-form :model="updatefrom">-->
    <!--          <el-form-item label="活动名称" :label-width="formLabelWidth">-->
    <!--            <el-input v-model="updatefrom.name" autocomplete="off"></el-input>-->
    <!--          </el-form-item>-->
    <!--          <el-form-item label="活动区域" :label-width="formLabelWidth">-->
    <!--            <el-select v-model="updatefrom.date" placeholder="请选择活动区域">-->
    <!--              <el-option label="区域一" value="shanghai"></el-option>-->
    <!--              <el-option label="区域二" value="beijing"></el-option>-->
    <!--            </el-select>-->
    <!--          </el-form-item>-->
    <!--        </el-form>-->
    <!--        <div slot="footer" class="dialog-footer">-->
    <!--          <el-button @click="openUpdate()">取 消</el-button>-->
    <!--          <el-button type="primary" @click="openOk('修改成功');UpdateData = false">确 定</el-button>-->
    <!--        </div>-->
    <!--      </el-dialog>-->
    <!--    </div>-->
    <div>
      <el-dialog title="新 增" :before-close="opensaves" :visible.sync="opensave">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="基本信息" name="first">
            <el-descriptions title="基本信息" column="2">
              <el-descriptions-item id="filiNumbers" label="档案号">{{ formData.fileNumber }}</el-descriptions-item>
              <el-descriptions-item label="姓名">{{ formData.name }}</el-descriptions-item>
              <el-descriptions-item label="性别">{{ formData.sex }}</el-descriptions-item>
              <el-descriptions-item label="年龄">{{ formData.age }}</el-descriptions-item>
            </el-descriptions>
            <el-descriptions column="1">
              <el-descriptions-item label="疾病史">{{ formData.medical_history }}</el-descriptions-item>
              <el-descriptions-item label="遗传史">{{ formData.famil_history }}</el-descriptions-item>
              <el-descriptions-item label="手术史">{{ formData.past_history }}</el-descriptions-item>
            </el-descriptions>
          </el-tab-pane>
          <el-tab-pane label="评估结果" name="third">
            <el-table
              v-loading="loading"
              :data="assData.slice((currentPages-1)*pageSizes,currentPages*pageSizes)"
              border
            >
              <el-table-column
                fixed
                prop="fileNumber"
                label="档案号"
              />
              <el-table-column
                prop="testTime"
                label="风险评估日期"
              />
              <el-table-column
                fixed="right"
                label="查看评估报告"
              >
                <template v-slot="scope">
                  <el-button type="primary" size="small" icon="el-icon-view" @click="openappe()">查看</el-button>
                </template>
              </el-table-column>
            </el-table>
            <el-pagination
              :current-page="currentPages"
              :page-sizes="[5, 10, 15, 20]"
              :page-size="pageSizes"
              layout="total, sizes, prev, pager, next, jumper"
              :total="totalNums"
              @size-change="handleSizeChanges"
              @current-change="handleCurrentChanges"
            />
          </el-tab-pane>
          <el-tab-pane label="确认分类" name="fourth">
            <el-form ref="formdata" :model="formdata">
              <el-descriptions title="确认分类">
                <el-descriptions-item label="确认分类">
                  <el-form-item>
                    <div>
                      <el-checkbox v-model="checked1" label="脂肪肝" name="type" value="脂肪肝" border
                                   @change="handleCheckboxClick('脂肪肝')"/>
                      <el-checkbox v-model="checked2" label="高血压" name="type" value="高血压" border
                                   @change="handleCheckboxClick('高血压')"/>
                      <el-checkbox v-model="checked3" label="高血糖" name="type" value="高血糖" border
                                   @change="handleCheckboxClick('高血糖')"/>
                      <el-checkbox v-model="checked4" label="高血脂" name="type" value="高血脂" border
                                   @change="handleCheckboxClick('高血脂')"/>
                    </div>
                  </el-form-item>
                </el-descriptions-item>
              </el-descriptions>
              <el-descriptions style="margin-top: 20px">
                <el-descriptions-item label="健康管理师">
                  <el-select v-model="formdata.usertype" placeholder="请选择">
                    <el-option
                      v-for="item in jkglsoptions"
                      :key="item.jkgl"
                      :label="item.label"
                      :value="item.jkgl"
                    />
                  </el-select>
                </el-descriptions-item>
              </el-descriptions>
            </el-form>
          </el-tab-pane>
        </el-tabs>
        <div slot="footer" class="dialog-footer">
          <el-button @click="opensaves()">取 消</el-button>
          <el-button type="primary" @click="openOk1('保存成功');">保 存</el-button>
        </div>
      </el-dialog>
    </div>
    <div>
      <el-dialog title="详细评估报告" :before-close="openapps" :visible.sync="openapp">
        <el-table
          v-loading="loading"
          :data="assData"
          border
        >
          <el-table-column
            fixed
            prop="fileNumber"
            label="档案号"
          />
          <el-table-column
            prop="testTime"
            label="风险评估日期"
          />
          <el-table-column
            prop="name"
            label="患者姓名"
          />
          <el-table-column
            prop="age"
            label="患者年龄"
          />
          <el-table-column


            prop="sex"
            label="患者性别"
          /><el-table-column
          prop="testTime"
          label="评测时间"
        /><el-table-column
          prop="num"
          label="评估总分"
        /><el-table-column
          prop="type"
          label="建议人群分类"
        />
        </el-table>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  data() {
    return {
      checked1:false,
      checked2:false,
      checked3:false,
      checked4:false,
      jkglsoptions: [{
        jkgl: '选项1',
        label: '黄金糕'
      }, {
        jkgl: '选项2',
        label: '双皮奶'
      }, {
        jkgl: '选项3',
        label: '蚵仔煎'
      }, {
        jkgl: '选项4',
        label: '龙须面'
      }, {
        jkgl: '选项5',
        label: '北京烤鸭'
      }],
      jkgl: '',
      checkList: [],
      activeName: 'first',
      updatefrom:
        {
          date: '',
          name: ''
        },
      opensave: false,
      UpdateData: false,
      formdata: {
        type: [],
        usertype: ''
      },
      form: '',
      openapp: false,
      // dialogFormVisible: false,
      currentPage: 1,
      input: '',
      pageSize: 5,
      totalNum: 0,
      currentPages: 1,
      inputs: '',
      pageSizes: 5,
      totalNums: 0,
      tableData: [],
      loading: false,
      formData: [],
      assData: [],
      checkbox:[]
    }
  },
  mounted() {
    this.queryDatas() // 调用初始化方法
    this.totalNum = this.tableData.length
  },
  methods: {
    handleCheckboxClick(type){
      console.log(type)
      if(this.checkbox.indexOf(type)!=-1){
        this.checkbox.splice(this.checkbox.indexOf(type),1)
      }else{
        this.checkbox.push(type)
      }
    },
    openOk1(msg) {
      console.log(this.checkbox)
      console.log(this.formData.c_id)
      axios.post('api/Classify/insertClassify', {id:this.formData.c_id,name:this.checkbox} ).then((returns) => {
        console.log(returns)
        if(returns.data.code === 200){
          this.$message({
            message: msg,
            type: 'success'
          })
          this.checkbox=[];
          this.formData=[];
          this.opensave = false
        }
      })
    },
    handleClick(row) {
      console.log(row)
    },
    handleSizeChange(val) {
      this.pageSize = val
      console.log(`每页 ${val} 条`)
    },
    handleCurrentChange(val) {
      this.currentPage = val
      console.log(`当前页: ${val}`)
    },
    handleSizeChanges(val) {
      this.pageSizes = val
      console.log(`每页 ${val} 条`)
    },
    handleCurrentChanges(val) {
      this.currentPages = val
      console.log(`当前页: ${val}`)
    },
    open(id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        axios.get('api/Classify/deleteByClassifyId?ber_id=' + id)
        this.queryDatas()
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
        this.queryDatas()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // Updates(id) {
    //   this.UpdateData = true
    //   let data = this.tableData.find((da) => da.name === id)
    //   this.updatefrom.name = data.name
    // },
    // openUpdate() {
    //   this.$confirm('是否退出修改?', '确认信息', {
    //     distinguishCancelAndClose: true,
    //     confirmButtonText: '取消',
    //     cancelButtonText: '退出'
    //   })
    //     .then(() => {
    //       this.$message({
    //         type: 'info',
    //         message: '放弃退出,继续修改'
    //       })
    //     })
    //     .catch(action => {
    //       this.$message({
    //         type: 'info',
    //         message: action === 'cancel'
    //           ? '放弃修改并离开页面'
    //           : '停留在当前页面'
    //       })
    //       if (action !== 'close') {
    //         this.UpdateData = false
    //       }
    //     })
    // },
    // openUAdd() {
    //   this.$confirm('是否退出添加?', '确认信息', {
    //     distinguishCancelAndClose: true,
    //     confirmButtonText: '取消',
    //     cancelButtonText: '退出'
    //   })
    //     .then(() => {
    //       this.$message({
    //         type: 'info',
    //         message: '放弃退出,继续添加'
    //       })
    //     })
    //     .catch(action => {
    //       this.$message({
    //         type: 'info',
    //         message: action === 'cancel'
    //           ? '放弃添加并离开页面'
    //           : '停留在当前页面'
    //       })
    //       if (action !== 'close') {
    //         this.dialogFormVisible = false
    //       }
    //     })
    // },
    opensaves() {
      this.$confirm('是否退出保存?', '确认信息', {
        distinguishCancelAndClose: true,
        confirmButtonText: '取消',
        cancelButtonText: '退出'
      })
        .then(() => {
          this.$message({
            type: 'info',
            message: '放弃退出'
          })
        })
        .catch(action => {
          this.$message({
            type: 'info',
            message: action === 'cancel'
              ? '放弃保存并离开页面'
              : '停留在当前页面'
          })
          this.opensave = false
        })
    },
    openOk(val) {
      const data = this.formdata
      this.$message({
        message: val,
        type: 'success'
      })
    },
    openapps() {
      this.$confirm('是否退出保存?', '确认信息', {
        distinguishCancelAndClose: true,
        confirmButtonText: '取消',
        cancelButtonText: '退出'
      })
        .then(() => {
          this.$message({
            type: 'info',
            message: '放弃退出'
          })
        })
        .catch(action => {
          this.$message({
            type: 'info',
            message: action === 'cancel'
              ? '放弃保存并离开页面'
              : '停留在当前页面'
          })
          if (action !== 'close') {
            this.openapp = false
          }
        })
    },
    opensavex(id) {
      const data = this.tableData.find((da) => da.id === id)
      this.formData = data
      console.log(this.formData)
      this.assessment(data.fileNumber)
      console.log(this.formData.diseaseid)
      if(this.formData.diseaseid === "脂肪肝"){
        this.checkbox.push("脂肪肝")
        this.checked1=true
      }
      if(this.formData.diseaseid === "高血压"){
        this.checkbox.push("高血压")
        this.checked2=true
      }
      if(this.formData.diseaseid === "高血糖"){
        this.checkbox.push("高血糖")
        this.checked3=true
      }
      if(this.formData.diseaseid === "高血脂"){
        this.checkbox.push("高血脂")
        this.checked4=true
      }
      this.formdata.usertype=this.formData.user_name;
    },
    queryDatas() {
      axios.post('api/Classify/queryClassify', { 'name': this.input }).then((returns) => {
        this.tableData = returns.data
      })
    },
    assessment(name) {
      this.assData = []
      alert(name)
      axios.get('api/Classify/queryriskkAssessmentByFileNumber?FileNumber=' + name).then((returns) => {
        this.assData.push(returns.data.data)
      })
    },
    openappe() {
      // const datas = this.assData.find((da) => da.id === id)
      // this.assData[0] = datas
      console.log(this.asedatas)
      this.assData[0].num = this.assData[0].zz1 + this.assData[0].zz2 + this.assData[0].zz3 + this.assData[0].zz4 + this.assData[0].zz5 + this.assData[0].zz6 + this.assData[0].zz7 + this.assData[0].zz8 + this.assData[0].zz9
      if (this.assData[0].type >= 0 && this.assData[0].type <= 19) {
        this.assData[0].type = '正常'
      } else if (this.assData[0].num >= 20 && this.assData[0].num <= 27) {
        this.assData[0].type = '脂肪肝'
      } else if (this.assData[0].num >= 28 && this.assData[0].num <= 33) {
        this.assData[0].type = '高血压'
      } else if (this.assData[0].num >= 34 && this.assData[0].num <= 39) {
        this.assData[0].type = '高血糖'
      } else if (this.assData[0].num >= 40 && this.assData[0].num < 45) {
        this.assData[0].type = '高血脂'
      } else {
        this.assData[0].type = '超过正常判断范围'
      }
      this.openapp = true
    }
  }
}
</script>
